import 'package:boss/ui/page/role/page/roleDetail/provider/role_detail_provider.dart';
import 'package:boss/ui/page/role/page/rolePermCon/role_perm_con_page.dart';
import 'package:boss/ui/page/role/provider/role_provider.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/form/base_text_form_field.dart';
import 'package:boss/ui/widget/title_row_button.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';

class RoleDetailBrowser extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: SingleChildScrollView(
              padding: EdgeInsets.symmetric(horizontal: 30.w),
              child: Consumer<RoleDetailProvider>(
                builder: (context, provider, _) => Column(
                  children: <Widget>[
                    BaseTextFormField(
                      prefixText: '角色',
                      hintText: '请输入角色',
                      isRequired: true,
                      initialValue: provider.role.roleName,
                      onChanged: (value) {
                        provider.role.roleName = value;
                      },
                    ),
                    TitleRowButton(
                      title: '角色权限',
                      value: '去设置',
                      onTap: () {
                        Navigator.pushNamed(context, RolePermCon.pageName);
                      },
                    ),
                  ],
                ),
              )),
        ),
        FixedBottomBtn(title: '保存', onTap: () => _save(context)),
      ],
    );
  }

  _save(BuildContext context) {
    final roleDetailProvider = Provider.of<RoleDetailProvider>(context, listen: false);
    final roleProvider = Provider.of<RoleProvider>(context, listen: false);
    final role = roleDetailProvider.role;
    role.permissions = roleDetailProvider.perms;

    roleProvider.saveRole(roleDetailProvider.role);
  }
}
